//
//  NewFeatureCell.m
//  weibo
//
//  Created by hp on 16/5/3.
//  Copyright © 2016年 hp. All rights reserved.
//

#import "NewFeatureCell.h"
// 省略mas_开头
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import <Masonry.h>
@interface NewFeatureCell()
@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UIButton *startBtn;
@end

@implementation NewFeatureCell


- (void)setImageIndex:(int)imageIndex
{
    _imageIndex = imageIndex;
    self.bgImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%i",_imageIndex+1]];
    if (_imageIndex==2) {
        
        self.startBtn.hidden = NO;
    } else {
        self.startBtn.hidden = YES;
    }
}


- (UIImageView *)bgImageView
{
    if (_bgImageView==nil) {
        _bgImageView = [[UIImageView alloc] init];
    }
    return _bgImageView;
}


- (UIButton *)startBtn
{
    if (_startBtn==nil) {
        _startBtn = [[UIButton alloc] init];
        [_startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_button"] forState:UIControlStateNormal];
        [_startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_button_highlighted"] forState:UIControlStateHighlighted];
        [_startBtn setHidden:YES];
        [_startBtn addTarget:self action:@selector(startBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _startBtn;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.bgImageView];
        [self.contentView addSubview:self.startBtn];
        
        [self.bgImageView makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.equalTo(self.contentView);
        }];
        
        [self.startBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView.centerX);
            make.centerY.equalTo(self.contentView.centerY);
            // 372 × 85
            make.width.equalTo(372/2);
            make.height.equalTo(85/2.0);
        }];
        
    }
    return self;
}


- (void)startBtnPressed:(UIButton *)btn
{
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSwitchRootViewController object:nil userInfo:nil];
}
@end
